<?php
namespace EApiSwoole\Server;
use EApiSwoole\Console\Input;
class HttpServer extends ServerBase
{

    protected function initServerConfig()
    {
        $this->port = $this->app->make("config")->get("server.http.port");
        $this->host = $this->app->make("config")->get("server.http.host");
    }

    protected function createServer()
    {
        $this->server = new \Swoole\Http\Server($this->host, $this->port,SWOOLE_PROCESS);
        $this->server->set(array(
            'reactor_num'   => 1,     // reactor thread num
            'worker_num'    => 8,     // worker process num
            'backlog'       => 256,   // listen backlog
        ));
		$msg="IP地址:".swoole_get_local_ip()['ens33']."   端口:".$this->port." ";
		echo PHP_EOL;
echoSuccess($msg);

    }

    protected function initEvent()
    {
        $this->setEvent('sub', [
            'request' => 'onRequest'
        ]);
    }
    public function onRequest($request, $response)
    {
        if ($request->server['path_info'] == '/favicon.ico' || $request->server['request_uri'] == '/favicon.ico') {
            $response->end();
            return;
        }
       $this->app->singleton('request',$request);
       $return = $this->app->make('route')->match($request->server['request_uri'], "http", $request->server['request_method'],$request);
       $response->end($return);
    }
}